import type {
  DoctorParams,
  DoctorRes,
  FollowType,
  KnowledgeParams,
  KnowledgeRes,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderParams,
  ConsultOrderPage
} from '@/types/consult'
import type { PatientItem } from '@/types/user'
import { request } from '@/utils/request'

/**
 * 首页-查询推荐/减脂/饮食健康/关注页面--百科文章列表
 * @param params 请求查数 { type, current, pageSize }
 * @returns Prmoise对象
 */
export const getKnowLedgeListAPI = (params: KnowledgeParams) =>
  request<KnowledgeRes>('/patient/home/knowledge', 'GET', params)

/**
 * 首页-关注的医生列表
 * @param params { current, pageSize }
 * @returns Prmoise对象
 */
export const getDoctorListAPI = (params: DoctorParams) =>
  request<DoctorRes>('/home/page/doc', 'GET', params)

/**
 * 关注-关注操作
 * @param type topic百科话题,knowledge百科文章,doc医生,disease疾病
 * @param id 对应的id
 * @returns Prmoise对象
 */
export const followOrUnFollowAPI = (id: string, type: FollowType = 'doc') =>
  request('/like', 'POST', { id, type })

/**
 * 获取科室
 */
export const getDepAllAPI = () => request<TopDep[]>('/dep/all')

/**
 * 上传文件/图片
 * @param file fd对象 multipart/form-data
 * @returns Prmoise对象
 */
export const uploadImageAPI = (file: File) => {
  // 实例化 FormData 对象
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

/**
 * 问诊-支付页面-计算就诊信息和抵扣信息
 * @param params 问诊订单预支付传参
 * @returns Prmoise对象
 */
export const getPreConsultOrderAPI = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

/**
 * 问诊-支付页面-计算就诊信息和抵扣信息
 * @param params 问诊订单预支付传参
 * @returns Prmoise对象
 */

export const getPatientInfoAPI = (id: string) => request<PatientItem>(`/patient/info/${id}`)

/**
 * 问诊-保存/修改问诊订单
 * @param data 请求对象
 * @returns Prmoise对象
 */
export const createOrderIdAPI = (data: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

/**
 * 问诊-支付问诊订单
 * @param params 请求对象
 * @returns Prmoise对象
 */
export const getConsultPayAPI = (params: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

/**
 * 问诊-查询订单详情信息-找医生、极速问诊和开药问诊
 * @param orderId 订单id
 * @returns Promise对象
 */
export const getConsultOrderDetailAPI = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

/**
 * 查看医生开的处方
 * @param id
 * @returns Promise对象
 */
export const getConsultPreAPI = (id: string) =>
  request<Image>(`/patient/consult/prescription/${id}`)

/**
 * 问诊-订单-评价医生
 * @param data 请求参数
 * @returns Promise对象
 */
export const evaluateDocAPI = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request('/patient/order/evaluate', 'POST', data)

/**
 * 订单-取消订单
 * @param id 订单id
 * @returns Promise对象
 */
export const cancelOrderAPI = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

/**
 * 问诊记录-订单列表-找医生、极速问诊、开药问诊
 * @param params 请求对象
 * @returns Promise对象
 */
export const getConsultOrderListAPI = (params: ConsultOrderParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

/**
 * 订单-删除订单
 * @param id 订单id
 * @returns Promise对象
 */
export const deleteOrderAPI = (id: string) => request(`/patient/order/${id}`, 'DELETE')
